Ext.namespace('ZZExt');

ZZExt.LoginWindow = Ext.extend(Ext.Window, {
	form:null,
	url:'operator!login.action',//提交登陆验证的url
	constructor : function(config) {
		Ext.apply(this,config);
		this.form = new Wlanauth.BaseFormPanel({
			baseCls:"x-plain",
			padding:10,
			defaults:{xtype:'textfield',anchor:'98%',allowBlank:false},
			items:[{  
				name:'entity.username',
				fieldLabel:'用户名',
			    cls:'username',
			    allowBlank:false
			   },{
			   name:'entity.password',
			   inputType:'password',
			   cls:'password',
			   fieldLabel:'密&nbsp;&nbsp; 码',
			   allowBlank:false
		   }]
		});
		var _html= '<div style="width:100%;height:60px;line-height:30px;color:#FFFFFF;background:url(images/topbg.png)">'
			_html+='<div style="float:left;padding-left:10px;"><img src="images/ChinaUnicom.png" style="height:50px;float:left"/></div>';
			_html+='<div class="sitetitle">无线宽带接入认证系统管理后台</div>';
			_html+='</div>';
			
		ZZExt.LoginWindow.superclass.constructor.call(this, {
			width : 440,
			title : "用户登录",
			iconCls:'app-login',
			closable:false,
			closeAction:'hide',
			frame:true,
			resizable:false,
			items:[{  
				html:_html
		    },this.form],
			buttons:[{
		      text:'登录',
		      handler:this.onLoginIn,
		      scope:this
		   },{
		      text:'重置',
		      handler:this.onReset,
		      scope:this
	       },{
	          text:'取消',
	          handler:this.onCancel,
	          scope:this
	         }]
			
		});
	},
	init:function(user){
		this.form.getForm().reset();
		if(user){
			this.form.getForm().findField('entity.username').setValue(user.username);
		}
	},
	onLoginIn:function(arg0,arg1){
		var _form=this.form.getForm();
		if(_form.isValid()){
			_form.submit({
				url:this.url,
				scope:this,
				waitMsg:'正在验证，请耐心等后...',
				success:this.doLoginSuccess
			});
		}
		else Ext.Msg.alert('系统提示','请正确填写各项！');
	},
	onReset:function(){
		this.form.getForm().reset();
	},
	onCancel:function(){
		window.close();
	},
	doLoginFailure:function(form,action){
    	var obj=action.result;
    	Ext.Msg.alert('系统提示','登录失败 :<br/> '+obj.msg);
    },
    doLoginSuccess:function(form,action){
    	this.hide();
    	window.location.href='welcome3G.jsp';
    }
	
});
